<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-1-28
 * Time: 下午11:10
 * To change this template use File | Settings | File Templates.
 */
class Model_Cfg_EntityHeader extends Jwawa_BaseModel
{

    public static function countEntityHeaderListBySbr($sbr){
        $sql = "SELECT count(*) c
                FROM cfg_entity_headers
                WHERE is_deleted = 'N' ";
        $sql .= $sbr->build(true);

        $stmt = self::createDefaultStmt(self::getDb(), $sql);
        $stmt->setProperties($sbr->getSearchItems());
        $stmt->execute();
        $rst = $stmt->fetchObj();

        return $rst->c;
    }

    public static function findEntityHeaderListBySbr($sbr){
        $sql = "SELECT id,
                       entity_name,
                       entity_code
                FROM cfg_entity_headers
                WHERE is_deleted = 'N'";
        $sql .= $sbr->build();

        $stmt = self::createDefaultStmt(self::getDb(), $sql);
        $stmt->setProperties($sbr->getSearchItems());
        $stmt->execute();
        $rst = $stmt->fetchAllObj();

        return $rst;
    }

    public static function findAllEntities(){
        $sql = "SELECT ceh.id,
                    ceh.entity_code,
                    ceh.create_time,
                    ceh.create_by,
                    ceh.update_time,
                    ceh.update_by
                FROM cfg_entity_headers ceh
                WHERE ceh.is_deleted = 'N'";

        $stmt = self::createDefaultStmt(self::getDb(), $sql);
        $stmt->execute();
        $entityHeaderList = $stmt->fetchAllObj();
        return $entityHeaderList;
    }
}
